﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.DAL;
using System.Collections.Generic;


namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class TR_ScholarshipDtls : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        InitialData_BLL iniData = new InitialData_BLL();
        IJobSiteBLL jBLL = new JobSiteBLL();
        JobSiteInfo info = new JobSiteInfo();
        ConvertNullable cn = new ConvertNullable();
        TrainingCoursesInfo courseInfo = new TrainingCoursesInfo();
        TrainingCoursesDAL courseDAL = new TrainingCoursesDAL();
        ITrainingCoursesQuotaBLL qBLL = new TrainingCoursesQuotaBLL();
        ITrainingCoursesTrainerBLL tBLL = new TrainingCoursesTrainerBLL();
        ITrainingLecturerSkillsBLL lSkillBLL = new TrainingLecturerSkillsBLL();
        IEmployeeBLL EmpBLL = new EmployeeBLL();
        TrainingCoursesDesDtlsBLL CDesBLL = new TrainingCoursesDesDtlsBLL();
        TrainingScholarshipBLL SchBLL = new TrainingScholarshipBLL();
        TR_SchlarshipDtlsBLL SchDtlsBLL = new TR_SchlarshipDtlsBLL();
        TrainingScholarshipDtlsBLL TrSchDtlsBLL = new TrainingScholarshipDtlsBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                
                LoadDataGrid1();
                LoadDetail();
            }

        }
        //===================================== สาขาวิชาที่พิจารณาให้ทุน ===========================================
        private void LoadDataGrid1()
        {
           
                string TrainSeq = Request.QueryString["Sequence"].ToString();
                DataSet ListDataCommand = SchDtlsBLL.GetDataSchGroup(TrainSeq);
                DataTable table = ListDataCommand.Tables[0];
                RadGrid1.DataSource = ListDataCommand.Tables[0];
                RadGrid1.DataBind();           
        }
        private void LoadDetail()
        {
            string strScholarSeq = Request.QueryString["Sequence"].ToString();
            DataSet ListDataCommand = SchBLL.GetData(strScholarSeq);
            DataTable table = ListDataCommand.Tables[0];
            if (table.Rows.Count > 0)
            {
                lbScholaType.Text = table.Rows[0]["scholar_type_descr"].ToString();
                lbScholarFund.Text = table.Rows[0]["scholar_fund_descr"].ToString();
                lbEduDegrees.Text = table.Rows[0]["edu_degree_name"].ToString();
                lbCountry.Text = table.Rows[0]["country_name"].ToString();
                lbYearEnd.Text = table.Rows[0]["edu_year_end"].ToString();
                lbYearStart.Text = table.Rows[0]["edu_year_start"].ToString();
                lbDateSignStart.Text = table.Rows[0]["date_sign_start"].ToString();
                lbDateSignEnd.Text = table.Rows[0]["date_sign_end"].ToString();
                lbTotalPrice.Text = table.Rows[0]["amount"].ToString();
                lbSubTotalPrice.Text = table.Rows[0]["amount"].ToString();
            }
        }

        protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32(RadGrid1.Items[e.Item.ItemIndex]["scholar_group_seq"].Text);
                SchDtlsBLL.DeleteSchGroup(seq, ssMng.EmpSeqI);
            }
            else if (e.CommandName == "AddData")
            {
                UpdateUI1("AddNew");
            }
            LoadDataGrid1();
        }

        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {

        }
        protected void btnSave1_Click(object sender, EventArgs e)
        {

            SchDtlsBLL.InsertSchGroup(txtScholaGroup.Text, Convert.ToInt32(txtTotalPrice.Text), Convert.ToInt32(Request.QueryString["Sequence"].ToString()), cn.ConvertNullInt(ssMng.EmpSeq));
            LoadDataGrid1();
            UpdateUI1("Save");
            
        }
        protected void btnUpdate1_Click(object sender, EventArgs e)
        {
            LoadDataGrid1();
            UpdateUI1("Save");
        }
        protected void btnCancel1_Click(object sender, EventArgs e)
        {
            UpdateUI1("Cancel");
            ClearControl1();
        }
        
        protected void ClearControl1()
        {
        }
        protected bool checkValidate1()
        {
            bool bOK = true;
            //string strJobSite = cbJobSite.SelectedValue;
            //string strQuota = txtquota.Text;

            //if (strJobSite.Length == 0)
            //{
            //    bOK = false;
            //    lblError2.Text = "* กรุณาเลือกหน่วยงาน";
            //}
            return bOK;
        }
        protected void UpdateUI1(string strCommand)
        {
            switch (strCommand)
            {
                case "Save":
                    PanelGrid1.Visible = true;
                    PanelAddData1.Visible = false;

                    break;

                case "AddNew":
                    PanelGrid1.Visible = false;
                    PanelAddData1.Visible = true;
                    btnUpdate1.Visible = false;
                    btnSave1.Visible = true;
                    txtScholaGroup.Text = string.Empty;
                    txtTotalPrice.Text = string.Empty;

                    break;

                case "Cancel":
                    PanelGrid1.Visible = true;
                    PanelAddData1.Visible = false;

                    break;

                case "Update":
                    PanelGrid1.Visible = false;
                    PanelAddData1.Visible = true;
                    btnSave1.Visible = false;
                    btnUpdate1.Visible = true;

                    break;
            }
        }
    }
}
